<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Plum Test</title>
<meta name="Generator" content="Vim/7.3">
<meta name="plugin-version" content="vim7.3_v6">
<meta name="syntax" content="javascript">
<meta name="settings" content="use_css,number_lines">
<style type="text/css">
<!--
html, body	{ height:100%; }
body { margin:0; padding:0; }
#flashContent { display:none; position: absolute; top: 0; left: 100px;}
pre { font-family: monospace; color: #f6f3e8; background-color: #000000; }
body { font-family: monospace; color: #f6f3e8; background-color: #000000; }
.lnr { color: #3d3d3d; background-color: #000000; }
.Conditional { color: #6699cc; }
.Constant { color: #99cc99; }
.Type { color: #ffffb6; }
.Comment { color: #7c7c7c; }
.Statement { color: #6699cc; }
.Number { color: #ff73fd; }
.Operator { color: #ffffff; }
.Identifier { color: #c6c5fe; }
.String { color: #a8ff60; }
.Function { color: #ffd2a7; }
.Keyword { color: #96cbfe; }
-->
</style>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script type="text/javascript" src="swfobject.js"></script>
        <script type="text/javascript">
            <!-- For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. --> 
            var swfVersionStr = "10.2.0";
            <!-- To use express install, set to playerProductInstall.swf, otherwise the empty string. -->
            var xiSwfUrlStr = "playerProductInstall.swf";
            var flashvars = {};
            var params = {};
            params.quality = "high";
            params.bgcolor = "#cccccc";
            params.allowscriptaccess = "sameDomain";
            params.allowfullscreen = "true";
            var attributes = {};
            attributes.id = "PlumTest";
            attributes.name = "PlumTest";
            attributes.align = "middle";
            swfobject.embedSWF(
                "PlumTest.swf", "flashContent", 
                "760", "700", 
                swfVersionStr, xiSwfUrlStr, 
                flashvars, params, attributes);
        </script>
</head>
<body>
<div id="flashContent"></div>
<div id="keys" style="position: absolute; top: 0; left: 780px; text-align: left; font-family: Arial;">
  <h2>Instructions</h2>
  <p><strong>s </strong>: stop</p>
  <p><strong>r </strong>: resume</p>
  <p><strong>q </strong>: reverse</p>
  <p><strong>p </strong>: speed up!</p>
  <p>Move mouse around to see xAtY in action</p>
</div>
<pre style="text-align: left">
<span class="lnr">  1 </span><span class="Keyword">package</span>
<span class="lnr">  2 </span><span class="Function">{</span>
<span class="lnr">  3 </span>    <span class="Keyword">import</span> com.atommica.plum.Plum;
<span class="lnr">  4 </span>    <span class="Keyword">import</span> com.atommica.plum.geom.ComplexPath;
<span class="lnr">  5 </span>    <span class="Keyword">import</span> com.atommica.plum.geom.CubicBezier;
<span class="lnr">  6 </span>    <span class="Keyword">import</span> com.atommica.plum.geom.Parametric;
<span class="lnr">  7 </span>
<span class="lnr">  8 </span>    <span class="Keyword">import</span> flash.display.Sprite;
<span class="lnr">  9 </span>    <span class="Keyword">import</span> flash.events.Event;
<span class="lnr"> 10 </span>    <span class="Keyword">import</span> flash.events.KeyboardEvent;
<span class="lnr"> 11 </span>    <span class="Keyword">import</span> flash.events.MouseEvent;
<span class="lnr"> 12 </span>    <span class="Keyword">import</span> flash.geom.Point;
<span class="lnr"> 13 </span>
<span class="lnr"> 14 </span>    <span class="Keyword">import</span> it.flashfuck.<span class="Keyword">debugger</span>.FPSMonitor;
<span class="lnr"> 15 </span>
<span class="lnr"> 16 </span>    <span class="Function">[</span>SWF(width=<span class="String">&quot;760&quot;</span>, height=<span class="String">&quot;700&quot;</span>, frameRate=<span class="String">&quot;50&quot;</span>, backgroundColor=<span class="String">&quot;#cccccc&quot;</span>)<span class="Function">]</span>
<span class="lnr"> 17 </span>    <span class="Keyword">public</span> <span class="Keyword">class</span> PlumTest <span class="Keyword">extends</span> Sprite
<span class="lnr"> 18 </span>    <span class="Function">{</span>
<span class="lnr"> 19 </span>        <span class="Keyword">public</span> <span class="Function">function</span> PlumTest()
<span class="lnr"> 20 </span>        <span class="Function">{</span>
<span class="lnr"> 21 </span>            <span class="Identifier">var</span> bez:CubicBezier = <span class="Operator">new</span> CubicBezier(
<span class="lnr"> 22 </span>                <span class="Operator">new</span> Point(<span class="Number">74</span>, <span class="Number">113</span>), <span class="Operator">new</span> Point(<span class="Number">179</span>, <span class="Number">61</span>),
<span class="lnr"> 23 </span>                <span class="Operator">new</span> Point(<span class="Number">389</span>, <span class="Number">23</span>), <span class="Operator">new</span> Point(<span class="Number">389</span>, <span class="Number">93</span>),
<span class="lnr"> 24 </span>                Parametric.ARC_LENGTH);
<span class="lnr"> 25 </span>
<span class="lnr"> 26 </span>            <span class="Identifier">var</span> bez2:CubicBezier = <span class="Operator">new</span> CubicBezier(
<span class="lnr"> 27 </span>                <span class="Operator">new</span> Point(<span class="Number">389</span>, <span class="Number">93</span>), <span class="Operator">new</span> Point(<span class="Number">389</span>, <span class="Number">163</span>),
<span class="lnr"> 28 </span>                <span class="Operator">new</span> Point(<span class="Number">191</span>, <span class="Number">245</span>), <span class="Operator">new</span> Point(<span class="Number">191</span>, <span class="Number">315</span>),
<span class="lnr"> 29 </span>                Parametric.ARC_LENGTH);
<span class="lnr"> 30 </span>
<span class="lnr"> 31 </span>            <span class="Identifier">var</span> bez3:CubicBezier = <span class="Operator">new</span> CubicBezier(
<span class="lnr"> 32 </span>                <span class="Operator">new</span> Point(<span class="Number">191</span>, <span class="Number">315</span>), <span class="Operator">new</span> Point(<span class="Number">190</span>, <span class="Number">394</span>),
<span class="lnr"> 33 </span>                <span class="Operator">new</span> Point(<span class="Number">622</span>, <span class="Number">454</span>), <span class="Operator">new</span> Point(<span class="Number">723</span>, <span class="Number">481</span>),
<span class="lnr"> 34 </span>                Parametric.ARC_LENGTH);
<span class="lnr"> 35 </span>
<span class="lnr"> 36 </span>            <span class="Identifier">var</span> curveDebug:Sprite = <span class="Operator">new</span> Sprite();
<span class="lnr"> 37 </span>            <span class="Identifier">this</span>.addChild(curveDebug);
<span class="lnr"> 38 </span>
<span class="lnr"> 39 </span>            <span class="Identifier">this</span>.bezier = <span class="Operator">new</span> ComplexPath(<span class="Function">[</span>bez, bez2, bez3<span class="Function">]</span>);
<span class="lnr"> 40 </span>            bezier.draw(curveDebug.graphics);
<span class="lnr"> 41 </span>
<span class="lnr"> 42 </span>            <span class="Identifier">this</span>.balls = <span class="Function">[]</span>;
<span class="lnr"> 43 </span>            <span class="Statement">for</span> (<span class="Identifier">var</span> i:uint = <span class="Number">0</span>; i &lt; MAX_BALLS; i++)
<span class="lnr"> 44 </span>            <span class="Function">{</span>
<span class="lnr"> 45 </span>                <span class="Comment">// Create new ball object and keep animation/sprite instances</span>
<span class="lnr"> 46 </span>                <span class="Identifier">var</span> ball:<span class="Type">Object</span> = <span class="Operator">new</span> <span class="Type">Object</span>();
<span class="lnr"> 47 </span>                ball.sprite = <span class="Operator">new</span> Sprite()
<span class="lnr"> 48 </span>
<span class="lnr"> 49 </span>                <span class="Comment">// Fill with random color and set border</span>
<span class="lnr"> 50 </span>                ball.sprite.graphics.beginFill(Math.random() * <span class="Number">0xFFFFFF</span>);
<span class="lnr"> 51 </span>                ball.sprite.graphics.lineStyle(<span class="Number">1</span>, <span class="Number">0x000000</span>)
<span class="lnr"> 52 </span>                ball.sprite.graphics.drawCircle(<span class="Number">0</span>, <span class="Number">0</span>, <span class="Number">10</span>);
<span class="lnr"> 53 </span>
<span class="lnr"> 54 </span>                <span class="Comment">// Draw a line in the middle to see how rotation works</span>
<span class="lnr"> 55 </span>                ball.sprite.graphics.moveTo(<span class="Number">0</span>, <span class="Number">-10</span>);
<span class="lnr"> 56 </span>                ball.sprite.graphics.lineTo(<span class="Number">0</span>, <span class="Number">10</span>);
<span class="lnr"> 57 </span>
<span class="lnr"> 58 </span>                <span class="Comment">// Add Ball to screen</span>
<span class="lnr"> 59 </span>                <span class="Identifier">this</span>.addChild(ball.sprite);
<span class="lnr"> 60 </span>
<span class="lnr"> 61 </span>                ball.animation = Plum.animate(ball.sprite, bezier, <span class="Function">{</span>
<span class="lnr"> 62 </span>                    <span class="String">'speed'</span>: <span class="Number">50</span>,
<span class="lnr"> 63 </span>                    <span class="String">'start'</span>: -ball.sprite.width * i,
<span class="lnr"> 64 </span>                    <span class="String">'orientToPath'</span>: <span class="Constant">true</span>,
<span class="lnr"> 65 </span>                    <span class="String">'fps'</span>: <span class="Identifier">this</span>.stage.frameRate
<span class="lnr"> 66 </span>                <span class="Function">}</span>);
<span class="lnr"> 67 </span>
<span class="lnr"> 68 </span>                <span class="Comment">// Save ball into our balls array to pause/resume eventually.</span>
<span class="lnr"> 69 </span>                <span class="Identifier">this</span>.balls.push(ball);
<span class="lnr"> 70 </span>            <span class="Function">}</span>
<span class="lnr"> 71 </span>
<span class="lnr"> 72 </span>            <span class="Identifier">this</span>.stage.addEventListener(KeyboardEvent.KEY_DOWN, <span class="Identifier">this</span>.keyPress);
<span class="lnr"> 73 </span>            <span class="Identifier">this</span>.stage.addEventListener(MouseEvent.MOUSE_MOVE, <span class="Identifier">this</span>.mouseMove);
<span class="lnr"> 74 </span>
<span class="lnr"> 75 </span>            <span class="Comment">// This sprite will be used to show how xAtY works.</span>
<span class="lnr"> 76 </span>            <span class="Identifier">this</span>.pointer = <span class="Operator">new</span> Sprite();
<span class="lnr"> 77 </span>            <span class="Identifier">this</span>.addChild(<span class="Identifier">this</span>.pointer);
<span class="lnr"> 78 </span>
<span class="lnr"> 79 </span>            <span class="Comment">// Add FPS monitor</span>
<span class="lnr"> 80 </span>            <span class="Identifier">this</span>.addChild(<span class="Operator">new</span> FPSMonitor());
<span class="lnr"> 81 </span>        <span class="Function">}</span>
<span class="lnr"> 82 </span>
<span class="lnr"> 83 </span>        <span class="Comment">/**</span>
<span class="lnr"> 84 </span><span class="Comment">         * Capture the mouse movement to show how xAtY works</span>
<span class="lnr"> 85 </span><span class="Comment">         */</span>
<span class="lnr"> 86 </span>        <span class="Keyword">private</span> <span class="Function">function</span> mouseMove(e:MouseEvent):void
<span class="lnr"> 87 </span>        <span class="Function">{</span>
<span class="lnr"> 88 </span>            <span class="Identifier">this</span>.pointer.graphics.clear();
<span class="lnr"> 89 </span>            <span class="Identifier">this</span>.pointer.graphics.beginFill(<span class="Number">0x0</span>);
<span class="lnr"> 90 </span>
<span class="lnr"> 91 </span>            <span class="Statement">for</span> each (<span class="Identifier">var</span> point:<span class="Type">Object</span> <span class="Statement">in</span> <span class="Identifier">this</span>.bezier.yAtX(e.stageX))
<span class="lnr"> 92 </span>            <span class="Function">{</span>
<span class="lnr"> 93 </span>                <span class="Identifier">this</span>.pointer.graphics.drawCircle(e.stageX, point.y , <span class="Number">5</span>);
<span class="lnr"> 94 </span>            <span class="Function">}</span>
<span class="lnr"> 95 </span>        <span class="Function">}</span>
<span class="lnr"> 96 </span>
<span class="lnr"> 97 </span>        <span class="Keyword">private</span> <span class="Function">function</span> keyPress(e:KeyboardEvent):void
<span class="lnr"> 98 </span>        <span class="Function">{</span>
<span class="lnr"> 99 </span>            <span class="Statement">for</span> each (<span class="Identifier">var</span> ball:<span class="Type">Object</span> <span class="Statement">in</span> <span class="Identifier">this</span>.balls)
<span class="lnr">100 </span>            <span class="Function">{</span>
<span class="lnr">101 </span>                <span class="Conditional">switch</span> (e.keyCode)
<span class="lnr">102 </span>                <span class="Function">{</span>
<span class="lnr">103 </span>                    <span class="Statement">case</span> KEY_S:
<span class="lnr">104 </span>                        ball.animation.pause();
<span class="lnr">105 </span>                        <span class="Conditional">break</span>;
<span class="lnr">106 </span>
<span class="lnr">107 </span>                    <span class="Statement">case</span> KEY_R:
<span class="lnr">108 </span>                        ball.animation.resume();
<span class="lnr">109 </span>                        <span class="Conditional">break</span>;
<span class="lnr">110 </span>
<span class="lnr">111 </span>                    <span class="Statement">case</span> KEY_Q:
<span class="lnr">112 </span>                        ball.animation.reversed = !ball.animation.reversed;
<span class="lnr">113 </span>                        <span class="Conditional">break</span>;
<span class="lnr">114 </span>
<span class="lnr">115 </span>                    <span class="Statement">case</span> KEY_P:
<span class="lnr">116 </span>                        ball.animation.speed = <span class="Number">200</span>;
<span class="lnr">117 </span>                        <span class="Conditional">break</span>;
<span class="lnr">118 </span>                <span class="Function">}</span>
<span class="lnr">119 </span>            <span class="Function">}</span>
<span class="lnr">120 </span>
<span class="lnr">121 </span>        <span class="Function">}</span>
<span class="lnr">122 </span>
<span class="lnr">123 </span>        <span class="Keyword">private</span> <span class="Keyword">const</span> KEY_S:uint = <span class="Number">83</span>;
<span class="lnr">124 </span>        <span class="Keyword">private</span> <span class="Keyword">const</span> KEY_R:uint = <span class="Number">82</span>;
<span class="lnr">125 </span>        <span class="Keyword">private</span> <span class="Keyword">const</span> KEY_Q:uint = <span class="Number">81</span>;
<span class="lnr">126 </span>        <span class="Keyword">private</span> <span class="Keyword">const</span> KEY_P:uint = <span class="Number">80</span>;
<span class="lnr">127 </span>
<span class="lnr">128 </span>        <span class="Keyword">private</span> <span class="Keyword">const</span> MAX_BALLS:uint = <span class="Number">20</span>;
<span class="lnr">129 </span>
<span class="lnr">130 </span>        <span class="Keyword">private</span> <span class="Identifier">var</span> bezier:ComplexPath;
<span class="lnr">131 </span>        <span class="Keyword">private</span> <span class="Identifier">var</span> balls:<span class="Type">Array</span>;
<span class="lnr">132 </span>        <span class="Keyword">private</span> <span class="Identifier">var</span> pointer:Sprite = <span class="Keyword">null</span>;
<span class="lnr">133 </span>    <span class="Function">}</span>
<span class="lnr">134 </span><span class="Function">}</span>
</pre>
</body>
</html>
